package com.lin.services.impl;

import com.lin.dao.PriceChangeDao;
import com.lin.pojo.PriceChange;
import com.lin.services.PriceChangeService;
import com.lin.utils.ShiroUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName PriceChangeServiceImpl
 * Package com.lin.services.impl
 *
 * @author hellcat
 * Date 2020/3/23
 * Description:
 * 🐾
 */
@Service
public class
PriceChangeServiceImpl implements PriceChangeService {

    @Autowired
    private PriceChangeDao priceChangeDao;

    @Override
    public List<PriceChange> getPriceChange(String waresId, String date) {
        try {
            String[] split = date.split(" - ");
            return priceChangeDao.getPriceChange(waresId, split[0], split[1], ShiroUtil.getUser().getStoreId());
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Map<String, Object> updateWaresPrice(String id, String price) {
        Map<String, Object> map = new HashMap<>();
        try {
            if (Double.parseDouble(price) < 0) {
                map.put("code", false);
                map.put("msg", "售价不能小于0");
            }
            priceChangeDao.updateWaresPrice(id, price, ShiroUtil.getUser().getStoreId());
            map.put("code", true);
        } catch (Exception e) {
            map.put("code", false);
            map.put("msg", "修改失败");
        }
        return map;
    }
}
